#ifndef __HEXAPOD_CONTROLLER_H__
#define __HEXAPOD_CONTROLLER_H__

#include "main.h"

#define MAX_MOTOR_NUM 18
#define MAX_LEG_NUM   6
#define HC_TIME_STAMP 0.05f
#define HC_KGJ_STAND_DEFAULT_ANG  0.0f
#define HC_XGJ_STAND_DEFAULT_ANG -0.3f
#define HC_HGJ_STAND_DEFAULT_ANG  0.8f

typedef struct
{
	uint8_t  flag;
    uint16_t time;
}KEY;

extern KEY key;

typedef enum
{
	HEXAPOD_READY2INIT,
    HEXAPOD_INIT,
	HEXAPOD_PENDING,
	HEXAPOD_STANDING,
	HEXAPOD_SITDOWN,
	HEXAPOD_READY2RUNNING,
	HEXAPOD_RUNNING,
	HEXAPOD_READY2SHUTDOWN,
	HEXAPOD_SHUTDOWN
}HEXAPOD_STATE;

enum RUNNING_STEP
{
    HC_BEGIN_INIT = 0,
	HC_MIDDLE_INIT,
	HC_FINISH_INIT,
	HC_CAL,
    HC_MOVE	
};

typedef struct
{
    uint8_t init_step;
	uint8_t stand_step;
	uint8_t sitdown_step;
	uint8_t running_step;
}HEXAPOD_STEP;

typedef struct
{
    uint16_t retry_time;
    float    running_time;
}HEXAPOD_TIME;

typedef struct
{
    uint8_t finish_flag;
}HEXAPOD_FLAG;

typedef struct HexapodController
{
    HEXAPOD_STATE state;
	HEXAPOD_STATE last_state;
	HEXAPOD_STEP  step;
	HEXAPOD_TIME  time;
	HEXAPOD_FLAG  flag;
}HexapodController;

extern HexapodController hc;

/* PFP */
uint8_t Hexapod_Init(void);
uint8_t Hexapod_Pending(void);
uint8_t Hexapod_Standing(void);
uint8_t Hexapod_Shutdown(void);
uint8_t Hexapod_Sitdown(void);
uint8_t Hexapod_Running(void);
#endif

